define(function(){
  // 左侧导航
  function shangouLeftFn(d1){
    var $shangouBox = $('#shangouBOX');
    var $LeftBox = $('#shangouLeft');
    var $dataObj = d1.data.categories;
    // console.log($dataObj);
    var $leftUl = $('<ul></ul>').css({
      "width":"25%",
      "height":"83%",
      "color":"#6d6d6d",
      "font-size":"0.25rem",
      "background":"#f8f8f8",
      "position":"fixed",
      "left":0,
      "overflow":"auto"
    }).appendTo($LeftBox)
    for(var $newSg of $dataObj){
      //获取所有li的id
      var $liidStr = $newSg.id;
      // console.log($liidStr);
      //获取所有导航名
      var $sgtitleStr = $newSg.name;
      // console.log($sgtitleStr);
      var $sgli = $('<li></li>').css({
        "width":"100%",
        "height":"0.9rem",
        // "line-height":"1rem",
        "border-bottom":"1px solid #e0e0e0",
        "padding-top":"0.1rem"
        // "text-align":"center",
        // "border-left":"0.1rem solid #ffd600"
      }).attr("id",$liidStr).appendTo($leftUl)

      var $lileft = $('<div></div>').css({
        "width":"0.1rem",
        "height":"90%",
        "float":"left"
      }).appendTo($sgli).addClass("leftDiv")
      var $liDiv = $('<div></div>').css({
        "width":"90%",
        "height":"90%",
        "line-height":"1rem",
        "text-align":"center",
        "float":"left"
      }).text($sgtitleStr).appendTo($sgli)
    }

  }

    function shangouMainFn(d3,id){

      var $d3Id = d3[id]
      // console.log($d3Id)
      // console.log(d3,id);

      var $mainBBox = $('#shangouMain');
      $mainBBox.html("");
      //获取商品div
      var $shangouMain = $('#shangouMain');
      var $mainUl = $('<ul></ul>').css({
        "width":"100%"
      }).appendTo($shangouMain)
      for (var $mainData of $d3Id){
        //图片

        var $mainImgStr = $mainData.img;
        // console.log($mainImgStr)
        //创建li
        var $shangouLi = $('<li></li>').css({
          "width":"100%",
          "height":"2rem",
          "font-size":"0.25rem",
          "border-bottom":"1px solid lightgray",
          "display":"flex",
          "align-items":"center",
          "justify-conten":"space-around"
        }).appendTo($mainUl);
        //盛放图片的div
        var $shangouimgDiv = $('<div></div>').css({
          "width":"40%",
          "height":"90%",
          "background":"url("+$mainImgStr+") no-repeat",
          "background-size":"100% 100%"
        }).appendTo($shangouLi)

        //右侧图片信息
        var $shangouTextdiv = $('<div></div>').css({
          "width":"50%",
          "height":"80%"
        }).appendTo($shangouLi)

        //图片名称
        var $imgTitleStr = $mainData.name;
        // console.log($imgTextStr)
        var $imgTitle = $('<p></p>').text($imgTitleStr).css({
          "white-space":"nowrap",
          "overflow":"hidden",
          "text-overflow":"ellipsis",
          "margin-bottom":"5px"
        }).appendTo($shangouTextdiv)

        //精选
        if($mainData.source_id == "1"){
          var $mainjx = $('<span></span>').text("精选").css({
            "display":"inline-block",
            "width":"0.6rem",
    				"font-size": "0.25rem",
    				"text-align": "center",
    				"border":"1px solid red",
    			  "border-radius":" 6px",
    				"color": "red",
            "margin-right":"0.1rem"
          }).appendTo($shangouTextdiv)
        }

        if($mainData.pm_desc == "买一赠一"){
          var $mainOne = $('<span></span>').text("买一赠一").css({
            "display":"inline-block",
            "width":"1.2rem",
            "font-size": "0.25rem",
    				"text-align": "center",
    			  "border-radius":" 6px",
    				"color": "white",
            "background-color":"red"
          }).appendTo($shangouTextdiv)
        }

        //量
        var $shangouKgStr = $mainData.specifics;
        var $kgP = $('<p></p>').text($shangouKgStr).css({
          "font-size": "0.25rem",
  				"color":"gray",
          "margin":"0.1rem auto"
        }).appendTo($shangouTextdiv)

        //价格
        var $shangouPrice = $('<div></div>').css({
          	"width": "100%",
            "position": "relative"
        }).appendTo($shangouTextdiv);
        //新价
        var $newStrsg = $mainData.partner_price;
        var $newspansg = $('<span></span>').text("￥"+$newStrsg).css({
          "color": "red",
  				"font-size":"0.23rem",
          "margin-right":"0.1rem"
        }).appendTo($shangouPrice);
        var $oldStrsg = $mainData.market_price;
        var $oldspansg = $('<span></span>').text("￥"+$oldStrsg).css({
          "color": "lightgray",
  				"font-size": "0.2rem",
  				"text-decoration":" line-through",
        }).appendTo($shangouPrice);

        var $price3sg = $('<span></span>').text("╋").css({
          "color": "#f40",
  				"width":"0.6rem",
  				"height": "0.6rem",
  				"line-height": "0.6rem",
  				"border-radius": "50%",
  				"border": "1px solid gray",
  				"text-align": "center",
  				"background": "#fff",

  				"position": "absolute",
  				"right": 0,
  				"bottom": 0,
  				"index":"100"
        }).appendTo($shangouPrice)
      }
    }
  return {
    shangouLeftFn:shangouLeftFn,
    shangouMainFn:shangouMainFn
  }

})
